import java.util.ArrayList;
import java.util.List;
import java.util.PriorityQueue;

public class Solution1383 {
    public int maxPerformance(int n, int[] speed, int[] efficiency, int k) {
        List<int[]> man=new ArrayList<>();
        for (int i=0;i<speed.length;i++){
            man.add(new int[]{speed[i],efficiency[i]});
        }
        man.sort((a,b)->(a[1]==b[1]?b[0]-a[0]:b[1]-a[1]));
        PriorityQueue<Integer> queue=new PriorityQueue<>();
        long sum=0;
        long ans=0;
        for (int i=0;i<k;i++){
            queue.offer(man.get(i)[0]);
            sum+=man.get(i)[0];
            ans=Math.max(ans,man.get(i)[1]*sum);
        }
        for (int i=k;i<n;i++){
            sum+=man.get(i)[0];
            queue.offer(man.get(i)[0]);
            int p=queue.poll();
            sum-=p;
            ans=Math.max(ans,sum*man.get(i)[1]);
        }
        return (int)(ans%1000000007);
    }

    public static void main(String[] args) {
        System.out.println(new Solution1383().maxPerformance(6,new int[]{2,10,3,1,5,8},new int[]{5,4,3,9,7,2},2));
    }
}
